package cn.t.xsmart.lifecycledemo;

import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import android.content.Context;
import android.util.Log;

/**
 * Author: by HeJingzhou on 2018/6/20 14:05.
 * <p>
 * Company: 北京天创时代信息技术有限公司
 * <p>
 * Email: tcowork@163.com
 * <p>
 * Effect:
 */
public class Dosomething implements LifecycleObserver {
    private String TAG = getClass().getSimpleName();

    private Context mContext;
    private Lifecycle mLifecycle;

    public Dosomething(Context mContext, Lifecycle lifecycle) {
        this.mContext = mContext;
        mLifecycle = lifecycle;
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void doCreateThing() {
        Log.i(TAG, "doCreateThing: ");
    }

    public void test() {
        if (mLifecycle.getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
            Log.i(TAG, "test: 这个时刻在跑这个OnResumed()方法");
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void doStart() {
        Log.i(TAG, "doStart: ");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    public void doResume() {
        Log.i(TAG, "doResume: ");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void doPause() {
        Log.i(TAG, "doPause: ");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void onStop() {
        Log.i(TAG, "onStop: ");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void doDestroy() {
        Log.i(TAG, "doDestroy: ");
    }
}
